﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Card.Web
{
    public partial class Logout : BasePage
    {
        #region 方法
        /// <summary>
        /// 来源Url
        /// </summary>
        private string TargetUrl
        {
            get
            {
                if (Request.QueryString["target"] != null)
                {
                    return Server.UrlDecode(Request.QueryString["target"]);
                }
                return string.Empty;
            }
        }
        #endregion

        #region
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.LogoutUser();
            }
        }
        #endregion

        #region
        private void LogoutUser()
        {
            Common.LoginUtility.ClearLoginIdentity();
            if (!string.IsNullOrEmpty(this.TargetUrl))
            {
                Response.Redirect(this.TargetUrl);
            }
            else if (this.Request.UrlReferrer != null && string.IsNullOrEmpty(this.Request.UrlReferrer.AbsoluteUri))
            {
                Response.Redirect(this.Request.UrlReferrer.AbsoluteUri);
            }
            else
            {
                Response.Redirect("/");
            }
        }
        #endregion
    }
}
